<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn"uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String s=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
%>
<html>
<head>

<%

  	String cpath = request.getContextPath();
  		String basePath = request.getScheme() + "://"
  				+ request.getServerName() + ":"
  				+ request.getServerPort() + cpath + "/";
%>
	<script src="<%=basePath%>js/rightButton.js" language="JavaScript" type="text/javascript"></script>
	<script src="<%=basePath%>js/MayaWebTools.js" language="JavaScript" type="text/javascript"></script>
<style> 
.DreamMenu {
    position:absolute;
    visibility:hidden;
    z-index:100;
    overflow:hidden;
    width:150px;
    background-color:buttonface;
    border:dimgray 1px solid !important;
    border:buttonhighlight menu menu buttonhighlight 2px outset;
    padding:1px !important;
    padding:1px 1px 1px 0px;
    font-size:12px;
}
 
.DreamMenu ul {
    margin:1px;
    border-bottom:buttonhighlight 1px solid;
    border-top:buttonshadow 1px solid;
}
 
.DreamMenu a {
    display:block;
    width:100%;
    padding:1px 2px 2px 20px;
    cursor:default;
    text-decoration:none;
    color:#000000;
}
 
.DreamMenu a:hover {
    background:highlight; 
    color:#ffffff;
}
</style> 
  <title>jFM - File Manager</title>
  <link rel="stylesheet" type="text/css" href="${url}/styles/jFM.css" />
  <%String type=(String)session.getAttribute("Type"); %>
</head>
  		<script language=javascript>
  			var downloadURL;
			function Display(url,name,size,lastModified){
				var imgTd=parent.document.getElementById("previewImg").parentNode;
				//在预览区要求不改变原图比例不铺张，所以没更新图片的时候重新设置img元素
				imgTd.innerHTML="<img onload='adaptImg(this);' id='previewImg' style='cursor:pointer;' border='1'>";
				var img=imgTd.firstChild;
				if(checkImgExt(url)){
					img.src=url;
				}else if(checkVideoExt(url)){
					img.src="../imagewang/ep.jpg";
				}else if(checkMayaExt(url)){
					img.src="../imagewang/ep2.jpg";
				}else{
					img.src="../imagewang/ep1.jpg";
				}
				
				
				//更新detail页面的素材信息
				var pixel=parent.width+"*"+parent.height;
				var fileName=top.D.Child.document.getElementById("fileName");
				if(fileName!=null && fileName!="undefined"){
					fileName.innerHTML=name;
				}
				var fileSize=top.D.Child.document.getElementById("fileSize");
				if(fileSize!=null && fileSize!="undefined"){
					fileSize.innerHTML=size;
				}
				var filePixel=top.D.Child.document.getElementById("filePixel")
				if(filePixel!=null && filePixel!="undefined"){
					filePixel.innerHTML=pixel;
				}
				var filePath=top.D.Child.document.getElementById("filePath")
				if(filePath!=null && filePath!="undefined"){
					filePath.innerHTML=url;
				}
				var lm=top.D.Child.document.getElementById("lastModified")
				if(lm!=null && lm!="undefined"){
					lm.innerHTML=lastModified;
				}
				top.D.Child.window.downloadURL=url;
				//IE FF 播放插件不同,IE的播放插件似乎会两次访问url而没有做编解码工作,导致中文路径不能播放
				url=encodeURI(url);
				
				img.onclick=function(){window.open(url,null,"top=150,left=150,scrollbars=yes,dialog=yes,modal=yes,width=750,height=620,resizable=yes");}
			}
			
			function autoShowImage(){
				if("<%=type %>"=="Shot"){
					var shotElementWin=top.D.Child.document.getElementById("ShotElement").contentWindow;
					if(shotElementWin.isFromHere=1){	
						var params=document.getElementsByName("parameters");
						var v=params[0].value;
						vs=v.split(",");
						Display(vs[0],vs[1],vs[2],vs[3]);
					}
				}else{
					var params=document.getElementsByName("parameters");
					var v=params[0].value;
					vs=v.split(",");
					Display(vs[0],vs[1],vs[2],vs[3]);
//					hr = decodeURI(hr);// 将原hr（UTF8编码的字符串）转换成无编码的，交给Display函数统一编码转换。防止2次编码
				}
			}
			function checkImgExt(url){
    			 //这里设置允许的扩展名
				var AllowExt=".jpg|.gif|.jpeg|.png|.bmp";
				var ExtOK=false;
				var ArrayExt;
				if(AllowExt.indexOf('|')!=-1){
   					ArrayExt=AllowExt.split('|');
					for(i=0;i<ArrayExt.length;i++){
						if(url.toLowerCase().indexOf(ArrayExt[i])!=-1){
							ExtOK=true;
							break;
						}
					}
				}else{
					ArrayExt=AllowExt;
					if(ext.toLowerCase()==ArrayExt){
						ExtOK=true;
					}
				}
				return ExtOK;
			}
			function checkVideoExt(url){
				//这里设置允许的扩展名
				var AllowExt=".avi|.mov";
				var ExtOK=false;
				var ArrayExt;
				if(AllowExt.indexOf('|')!=-1){
					ArrayExt=AllowExt.split('|');
					for(i=0;i<ArrayExt.length;i++){
						if(url.toLowerCase().indexOf(ArrayExt[i])!=-1){
							ExtOK=true;
							break;
						}
					}
				}else{
					ArrayExt=AllowExt;
					if(url.toLowerCase().indexOf(ArrayExt)!=-1){
						ExtOK=true;
					}
				}
				return ExtOK;
			}
			function checkMayaExt(url){
				//这里设置允许的扩展名
				var AllowExt=".ma|.mb";
				var ExtOK=false;
				var ArrayExt;
				if(AllowExt.indexOf('|')!=-1){
					ArrayExt=AllowExt.split('|');
					for(i=0;i<ArrayExt.length;i++){
						if(url.toLowerCase().indexOf(ArrayExt[i])!=-1){
						ExtOK=true;
						break;
						}
					}
				}else{
					ArrayExt=AllowExt;
					if(url.toLowerCase().indexOf(ArrayExt)!=-1){
					ExtOK=true;
					}
				}
				return ExtOK;
			}
			
			
			
		function UrlToMayaPath(value)
		{
			var urlLocation = value.indexOf("/Project/scenes/");
			if ( urlLocation != -1 )
			{
				urlLocation = urlLocation+9;  // 指到 scenes
				return value.substring(urlLocation,value.length);
//				window.open('mel:file -f -options "v=0;p=17" -o "' + filePath + '"');
			}
		}	
		
		function openMaya(value)
		{
		
			var filePath = UrlToMayaPath(value);
			window.location.href='mel:file -f  -o "' + filePath + '"';
		}		
		function ReferenceFile(value,fileName)
		{
			var filePath = UrlToMayaPath(value);
			fileName = fileName.substring(0,fileName.length-3);
	//		alert( fileName);
			window.location.href = 'mel:file -r -gl -loadReferenceDepth "all" -shd "renderLayersByName" -namespace "'+fileName+'" -options "v=0;p=17" "'+filePath+'"';
		}
		function ImportFile(value,fileName)
		{
			var filePath = UrlToMayaPath(value);
			fileName = fileName.substring(0,fileName.length-3);
	//		alert( fileName);
			window.location.href = 'mel:file -import  -ra true -namespace  "'+fileName+'"-options "v=0;p=17"  -pr -loadReferenceDepth "all"  "'+filePath+'"';
			
		}
</script>



<body bgcolor="#FFFFFF" onload="autoShowImage();MWT_Embed('MCP','commandportDefault');" menu='menu'>
<table width="1249">
<tr>




<td width="23%" >
<c:if test="${!fatalerror}"> 

<form name="files" action="${self}${path}" method="get">

<table border="1" cellpadding="3" cellspacing="0" width="284">
<tbody>

<tr>
<td colspan="5" class="title">
<c:set var="parentlink" value="" scope="request"/>

<c:forEach var="parent" items="${folder.parents}" varStatus="status">
<c:choose> 
  <c:when test="${parent.isActive}"> 
  </c:when> 
  <c:otherwise> 
    ${parent.display} 
  </c:otherwise> 
</c:choose>  
<c:if test="${!status.last}">           
	<c:set var="parentlink" value="${self}${parent.link}" scope="request"/>
</c:if> 
</c:forEach>

&nbsp;

<c:if test="${parentlink != ''}">
<a href="${parentlink}"><img src="${url}/img/up-one-dir.gif" title="to parent folder" width="16" height="16" alt="UP" border="0"></a>
  </c:if>
</td>
</tr>


<c:forEach var="file" items="${folder.files}">
	<div id="menu${file.id}" class='DreamMenu'> 
	
		<c:if test='${fn:endsWith((file.name),".ma")}'>
			<a href="javascript:openMaya('${path}${file.name}')">OpenWithMaya</a>
			<a href="javascript:ReferenceFile('${path}${file.name}','${file.name}')">Reference</a>
			<a href="javascript:ImportFile('${path}${file.name}','${file.name}')">Import</a>
		</c:if>
		<c:if test='${fn:endsWith((file.name),".mb")}'>
			<a href="javascript:openMaya('${path}${file.name}')">OpenWithMaya</a>  
			<a href="javascript:ReferenceFile('${path}${file.name}','${file.name}')">Reference</a>
			<a href="javascript:ImportFile('${path}${file.name}','${file.name}')">Import</a>
		</c:if>
		<ul></ul> 
		<a href="${file.url}?isDownload=1">下载</a>
		<ul></ul>   
 		<c:if test="${!file.isDirectory}"> 
			<a href="${self}${path}?command=Delete&index=${file.id}" onclick="return   confirm('Confirm Delete')">删除</a>
		</c:if>
 
	</div>

<tr>

<td name="${file.name}" class="row-left" width="274"><small><c:choose> 
  <c:when test="${file.isDirectory}"> 
    <a href="${self}${file.path}/?sort=dd"><img src="${url}/img/folder.gif" title="folder" width="16" height="16" alt="DIR" border="0"></a>
    <a href="${self}${file.path}/?sort=dd">${file.name}</a>
  </c:when> 
  <c:otherwise>
  <c:choose> 
   <c:when test="${empty fileName ? false : fn:startsWith( (file.name), fileName) }"> 
	  <a><img src="${url}/img/file.gif" title="file" width="16" height="16" alt="FILE" border="0"></a>
	  <b><a menu='menu${file.id}' href="javascript:Display('${file.url}','${file.name}','${file.size}','${file.lastModified}')"><font color='red'>${file.name}</font></a></b>
   </c:when>
   <c:otherwise>
	 <a ><img src="${url}/img/file.gif" title="file" width="16" height="16" alt="FILE" border="0"></a>
 	 <a menu='menu${file.id}' href="javascript:Display('${file.url}','${file.name}','${file.size}','${file.lastModified}')">${file.name}</a>
	 <input type="hidden" name="parameters" value="${file.url},${file.name},${file.size},${file.lastModified}">
	</c:otherwise>
	
	</c:choose>
  </c:otherwise>
  
</c:choose>  </small></td>
</tr>

</c:forEach>






</tbody>
</table>

</form>







</c:if>


</td>
</tr>
</table>


</body>
</html>